home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / fakemode / fakeshow.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-16  |  5.2 KB  |  162 lines

  1. //FAKESHOW - the FakeMode .TGA viewer           (c) 1993,94 by Yaka/Xography
  2. //3840 Colors simultanously on screen (with register compatible VGA cards)!
  3.  
  4. //This program is not perfect, I just wrote it in a hurry as an example how
  5. //FakeMode may be used. Feel free to add your own ideas!
  6. //(Read FAKEMODE.DOC for more information about FakeMode)
  7.  
  8. #include <conio.h>
  9. #include <io.h>
  10. #include <fcntl.h>
  11. #include "fakemode.h"
  12.  
  13. unsigned char buf[48];
  14. unsigned char viewcolor[16][16][16];
  15.  
  16.  
  17. void putdithpixel(unsigned int x, unsigned int y, unsigned char red, unsigned char green, unsigned char blue) {
  18. // This routine dithers the colors and puts the pixel on the screen.
  19. // The dithering is not as good as the one in the routine below, but it
  20. // causes less flicker.
  21. // Check out the commented routine below to see how dithering can interfere
  22. // with FakeMode's pageflipping.
  23.   unsigned char r,g,b;
  24.  
  25.   r=red >> 4;
  26.   if (((red & 8)>0) && ((((x+y) % 2)^((x/4)%2)^((y/8)%2))==0) && (r<15)) r++;
  27.   g=green >> 4;
  28.   if (((green & 8)>0) && ((((x+y) % 2)^((x/4)%2)^((y/8)%2))!=0) && (g<15)) g++;
  29.   b=blue >> 4;
  30.   if (((blue & 8)>0) && ((((x+y) % 2)^((x/4)%2)^((y/8)%2))!=0) && (b<15)) b++;
  31.  
  32.   F_putsmallpixel(x,y,r,g,b);
  33. }
  34.  
  35. /*void putdithpixel(unsigned int x, unsigned int y, unsigned char red, unsigned char green, unsigned char blue) {
  36. // This routine dithers the colors. This dithering method tends to flicker
  37. // because it's a 50/50 chessboard dithering that interferes with the page
  38. // flipping. Perhaps you figure out a better way to do the dithering
  39. // (or leave it away) :)
  40.   unsigned char r,g,b;
  41.  
  42.   r=red >> 4;
  43.   if (((red & 8)>0) && (((x+y) % 2)==0) && (r<15)) r++;
  44.   g=green >> 4;
  45.   if (((green & 8)>0) && (((x+y) % 2)!=0) && (g<15)) g++;
  46.   b=blue >> 4;
  47.   if (((blue & 8)>0) && (((x+y) % 2)!=0) && (b<15)) b++;
  48.  
  49.   F_putsmallpixel(x,y,r,g,b);
  50. }*/
  51.  
  52. int loadimage(char *name) {
  53. // Tries to load the .TGA picture with the name 'name' to the screen.
  54. // Halves the width if > 320
  55. // Doubles the height if <= 200
  56.  
  57.   int handle,i,j,k;
  58.   unsigned int x,y,v;
  59.   unsigned char ar,ag,ab;
  60.   int width,height,yload;
  61.  
  62.   for (i=0; i<16; i++) {                //initialize color counter
  63.     for (j=0; j<16; j++) {
  64.       for (k=0; k<16; k++) {
  65.     viewcolor[i][j][k]=0;
  66.       }
  67.     }
  68.   }
  69.   if ((handle = open(name, O_RDONLY | O_BINARY))== -1) {return(1);}
  70.   read(handle,buf,18);
  71.   height=buf[15];                       //Calculate width/height from header
  72.   height*=256;
  73.   height+=buf[14];
  74.   width=buf[13];
  75.   width*=256;
  76.   width+=buf[12];
  77.   if (width>320) {                      //The following part paints half width
  78.     width-=640;
  79.     width*=3;
  80.     if (height<400) {yload=height;} else {yload=400;}
  81.     for (y=0; y<yload; y++) {
  82.       for (x=0; x<320; x+=8) {
  83.     read(handle,buf,48);
  84.     for (i=0; i<8; i++) {
  85.       v=buf[i*6+2]; v+=buf[i*6+5]; ar=v>>1;
  86.       v=buf[i*6+1]; v+=buf[i*6+4]; ag=v>>1;
  87.       v=buf[i*6]; v+=buf[i*6+3]; ab=v>>1;
  88.       if (height<=200) {
  89.         putdithpixel(x+i,y*2,ar,ag,ab);
  90.         putdithpixel(x+i,y*2+1,ar,ag,ab);
  91.       } else putdithpixel(x+i,y,ar,ag,ab);
  92.       viewcolor[ar>>4][ag>>4][ab>>4]=1;
  93.     }
  94.       }
  95.       if (width!=0) lseek(handle,width,SEEK_CUR);
  96.     }
  97.   } else {                              //This part is for full width
  98.     width-=320;
  99.     width*=3;
  100.     if (height<400) {yload=height;} else {yload=400;}
  101.     for (y=0; y<yload; y++) {
  102.       for (x=0; x<320; x+=16) {
  103.     read(handle,buf,48);
  104.     for (i=0; i<16; i++) {
  105.       ar=(buf[i*3+2]);
  106.       ag=(buf[i*3+1]);
  107.       ab=(buf[i*3]);
  108.       if (yload>200) {
  109.         putdithpixel(x+i,y,ar,ag,ab);
  110.       } else {
  111.         putdithpixel(x+i,y*2,ar,ag,ab);     //
  112.         putdithpixel(x+i,y*2+1,ar,ag,ab);   //
  113.         //F_putbigpixel(x+i,y,ar>>4,ag>>4,ab>>4);
  114.             //Use this alternatively to check F_putbigpixel
  115.       }
  116.       viewcolor[ar>>4][ag>>4][ab>>4]=1;
  117.     }
  118.       }
  119.       if (width!=0) lseek(handle,width,SEEK_CUR);
  120.     }
  121.   }
  122.   close(handle);
  123.   return(0);
  124. }
  125.  
  126. int main(int argc, char *argv[]) {
  127.   int i,j,k,colzahl;
  128.  
  129.   if (argc!=2) {
  130.     cprintf("\r\nFAKESHOW.EXE                                          (c) 1994 by Yaka/Xography\r\n");
  131.     cprintf("───────────────────────────────────────────────────────────────────────────────\r\n\n");
  132.     cprintf("Usage: FAKESHOW <unpacked Targafile.TGA>\r\n\n");
  133.   } else {
  134.     if (!F_isvga()) {cprintf("Sorry, but you need a VGA card to run this program.\r\n");}
  135.      else {
  136.       F_initgraph();                    //Initialize FakeMode.
  137.       F_setlumi(0);                     //Darken Screen.
  138.       i=loadimage(argv[1]);             //Load Image.
  139.       if (i==0) {                       //If Image was loaded correctly:
  140.     F_fadein();                     //Fade in Picture
  141.     getch();                        //Wait for keypress
  142.     F_fadeout();                    //Fade out picture
  143.     F_closegraph();                 //Close FakeMode.
  144.     colzahl=0;
  145.     for (i=0; i<16; i++) {          //Count colors displayed
  146.       for (j=0; j<16; j++) {
  147.         for (k=0; k<16; k++) {
  148.           if (viewcolor[i][j][k]==1) colzahl++;
  149.         }
  150.       }
  151.     }
  152.     cprintf("You have been looking at %i different colors!\r\n\n",colzahl);
  153.       } else {
  154.     F_closegraph();
  155.     cprintf("Could not open %s.\r\n\n",argv[1]);
  156.       }
  157.     }
  158.   }
  159.   while(kbhit()) getch();               //Empty keyboard buffer
  160.   return(0);
  161. }
  162.